/*************************************************************************
	> File Name: Composite.h
	> Author: Joker
	> Mail: mahongtao@foxmail.com 
	> Created Time: 2020-09-22 00:56:50
 ************************************************************************/

#ifndef __COMPOSITE_H__
#define __COMPOSITE_H__

#include <list>

using std::list;

//组合中的抽象基类
class Component
{
public:
    Component(){}
    virtual ~Component(){}

    virtual void Operation() = 0;

    virtual void ADD(Component * pChild);
    virtual void Remove(Component * pChild);
    virtual Component * GetChild(size_t index);
};

class Leaf
:public Component
{
public:
    Leaf(){}
    virtual ~Leaf(){}

    virtual void Operation();
};

class Composite
:public Component
{
public:
    Composite();
    ~Composite();

    virtual void Operation();

    virtual void ADD(Component * pChild);
    virtual void Remove(Component * pChild);
    virtual Component * GetChild(size_t index);

private:
    list<Component *> _listComponent; 
};

#endif
